<template>
  <div id="success">
    <div v-if="!show" class="success-tip">
      <div class="success-card">
        <div class="success-card-inner">
          <p class="card-tip">开通成功</p>
<!--          <p v-if="unBind.length !== 0" class="card-subTip">-->
<!--            你还可以继续绑定以下卡种-->
<!--          </p>-->
<!--          <p v-if="unBind.length === 0" class="card-subTip1">-->
<!--            目前您没有需要手动绑定的卡-->
<!--          </p>-->
          <div
            class="card-item"
            @click="bindCard(item)"
            v-for="(item, index) in unBind"
            :key="index"
          >
            {{ item.title }}
          </div>
        </div>
        <div class="success-img">
          <img src="../../assets/img/dui_gou.png" width="100%" />
        </div>
      </div>
      <div class="success-btn" @click="actionOver">
        <p class="success-btn-text">完成</p>
      </div>
    </div>
    <div v-else class="success-loading">
      <van-loading size="60px" type="spinner"></van-loading>
      <p>加载中...</p>
    </div>
  </div>
</template>

<script>
import { storage } from "../../plugins/storage";
import { Dialog } from "vant";
export default {
  data() {
    return {
      unBind: [],
      bind: [],
      show: true
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      this.verifySign();
      let arry = storage.get("cards");
      arry.forEach(item => {
        if (item.bindMode === "01") {
          this.bind.push(item.cardTypeId);
        }
        if (item.bindMode === "02") {
          this.unBind.push(item);
        }
      });
    },
    bindCard(data) {
      if (data.available === 1) {
        location.href = data.bindUrl;
      } else {
        Dialog.alert({
          title: "提示",
          message: "此卡不可用！"
        });
      }
    },
    async verifySign() {
      let back =
        location.href.split("?").length > 1 ? location.href.split("?")[1] : "";
      let res = await this.api.analysisData(back);
      if (res) {
        if (res.code === "40015") {
          this.$dialog
            .confirm({
              message: res.message,
              showCancelButton: false
            })
            .then(() => {
              location.href = "yi-code://home";
            });
        } else {
          this.show = false;
        }
      }
    },
    actionOver() {
      let obj = {
        cardTypeIds: this.bind
      };
      this.api.bindCard(obj).then(res => {
        if (res.ok) {
          // this.$router.push("/code");
          this.$router.replace("/code");
        }
      });
      // this.$router.push("/code");
    }
  }
};
</script>

<style lang="less" scoped>
#success {
  width: 100%;
  height: 100%;
  position: relative;
  background-image: url("../../assets/img/bind_bg.png");
  background-size: 100% 100%;

  .success-tip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    .success-card {
      background: #fff;
      width: 325px;
      /*height: 230px;*/
      height: 200px;
      border-radius: 10px;
      position: relative;
      .success-card-inner {
        /*padding: 45px 20px 20px 20px;*/
        padding: 45px 20px 20px 20px;
        text-align: center;
        .card-tip {
          color: #4663ff;
          font-size: 20px;
          letter-spacing: 1px;
          font-weight: 600;
          /*padding-top: 15px;*/
          padding-top: 45px;
        }
        .card-subTip {
          color: #666666;
          font-size: 14px;
          padding: 15px 0;
        }
        .card-subTip1 {
          color: #666666;
          font-size: 14px;
          padding-top: 45px;
        }
        .card-item {
          font-size: 14px;
          color: #4663ff;
          padding: 8px 0;
        }
      }
      .success-img {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        top: -25px;
        width: 50px;
        height: 50px;
      }
    }

    .success-btn {
      width: 160px;
      margin: 15px auto 0 auto;
      background: #4663ff;
      text-align: center;
      border-radius: 50px;
      .success-btn-text {
        font-size: 16px;
        color: #fff;
        padding: 15px 0;
      }
    }
  }

  .success-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
p {
  margin: 0;
  padding: 0;
}
</style>
